package com.sgb.kjwl.view.ui.adapter.material;

import android.content.Context;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.user.SkuItemAttrEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class SkuChildAdapter extends BaseRecycleAdapter<SkuItemAttrEntity.Child> {
    public SkuChildAdapter(Context context, List<SkuItemAttrEntity.Child> datas) {
        super(context, R.layout.item_sku_child, datas);

    }


    @Override
    public void convert(ItemViewHolder holder, final SkuItemAttrEntity.Child entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView tv_category_item = holder.getItem().findViewById(R.id.tv_category_item);
        if (entity.isEnabled() == false) {
            tv_category_item.setEnabled(false);
            tv_category_item.setTextColor(context.getResources().getColor(R.color.color_60666666));
            tv_category_item.setBackgroundColor(context.getResources().getColor(R.color.color_30F5F5F5));
        } else {
            tv_category_item.setBackground(context.getResources().getDrawable(R.drawable.select_bg));
        }

        tv_category_item.setSelected(entity.isChecked());

        tv_category_item.setOnClickListener(view -> {
            for (int i = 0; i < datas.size(); i++) {
                datas.get(i).setChecked(false);
            }
            if (onItemClick != null) {
                onItemClick.onItemClick(entity, holder.getIndex_position());
            }
            datas.get(holder.getIndex_position()).setChecked(true);
            notifyDataSetChanged();
        });
    }

}
